using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace hemsidan
{
	/// <summary>
	/// Summary description for ViewGallery.
	/// </summary>
	public partial class ViewGallery : Bases.Page
	{
		protected System.Web.UI.WebControls.Repeater rptImageList;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
			{
				GalleryId = int.Parse(Request.QueryString["GalleryId"]);
				Gallery = Entities.PhotoGallery.GetGalleryContent(GalleryId);
				LoadData();
			}
		}

		private void LoadData()
		{
			imgDisplay.ImageUrl = (string)Gallery.Rows[0]["Path"];

			dlImages.DataSource = Gallery;
			dlImages.DataBind();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.dlImages.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.dlImages_ItemCommand);

		}
		#endregion

		private int GalleryId
		{
			get 
			{
				if (this.Session["GalleryId"] == null)
					  return 0;
				  else
					  return (int)this.Session["GalleryId"];
			}
			set 
			{
				this.Session["GalleryId"] = value;
			}
		}
		private DataTable Gallery
		{
			get 
			{
				if (this.Session["Gallery"] == null)
					  return null;
				  else
					  return (DataTable)this.Session["Gallery"];
			}
			set { this.Session["Gallery"] = value; }
		}

		private void dlImages_ItemCommand(object source, DataListCommandEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
			{
				int photoId = (int)dlImages.DataKeys[e.Item.ItemIndex];
				DataRow[] rows = Gallery.Select("Id=" + photoId.ToString());
				imgDisplay.ImageUrl = (string)rows[0]["Path"];
				dlImages.SelectedIndex = e.Item.ItemIndex;
			}
		}
	

	}
}
